﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Metodesa.Logic;
using METODESA.Server.Data.METODESA.Entity;
using METODESA.Server.Data.METODESA.Nhibernate;

namespace Metodesa.Views.Shared
{
    public partial class Metodesa : System.Web.UI.MasterPage
    {
        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            Empleado usuario = EmpleadoLogic.getUser(teLogin.Text, tePassword.Text);
            if (usuario == null)
            {
                labelError.Visible = true;
                labelError.Text = "Usuario o contrasena no valida";
                labelError.ForeColor = Color.DarkRed;
            }
            else
            {
                labelName.Visible = true;
                labelName.Text =" "+ usuario.Nombre + " " + usuario.Apellido;
   
                Session.Add("User",usuario);
                panelEndLogin.Visible = true;
                panelStartLogin.Visible = false;
                panelWelcome.Visible = true;
                
                

            }
        }

        protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
        {
            Session.Add("User",null);
            Session.Abandon();
            panelEndLogin.Visible = false;
            panelStartLogin.Visible = true;
            panelWelcome.Visible = false;
            Server.Transfer("../../Views/Home/Index.aspx");
            
            
        }

        protected void Page_Load(object sender, EventArgs e)
        {

            HttpContext.Current.Response.Cache.SetExpires(DateTime.Now.AddYears(-10));
            HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            HttpContext.Current.Response.Cache.SetNoStore();

            if (Session["User"] != null)
            {
                Empleado usuario = (Empleado)Session["User"];
                labelName.Visible = true;
                labelName.Text = " " + usuario.Nombre + " " + usuario.Apellido;
                Session.Add("User", usuario);
                panelEndLogin.Visible = true;
                panelStartLogin.Visible = false;
                panelWelcome.Visible = true;
                Session.Timeout = 40;
            }
            else
            {
                panelEndLogin.Visible = false;
                panelStartLogin.Visible = true;
                panelWelcome.Visible = false;
            }

        }
    }


}
